package io.binghe.im.openai.common.httpclient;

import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;

import javax.net.ssl.SSLContext;

/**
 * @author binghe(微信 : hacker_binghe)
 * @version 1.0.0
 * @description
 * @github https://github.com/binghe001
 * @copyright 公众号: 冰河技术
 */
public class HttpClient {

    /**
     * 创建 HttpClient 客户端代码
     **/
    public static CloseableHttpClient createSSLClientDefault() {
       try{
           // Trust all certificates
           SSLContext sslContext = SSLContextBuilder.create()
                   .loadTrustMaterial((chain, authType) -> true)
                   .build();
           // Set SSL context and hostname verifier
           SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
                   sslContext,
                   NoopHostnameVerifier.INSTANCE);

           return HttpClients.custom()
                   .setSSLSocketFactory(sslSocketFactory)
                   .build();
       }catch (Exception e){
           e.printStackTrace();
       }
       return HttpClientBuilder.create().build();
    }
}
